/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
// CheckFlags.h
//

#pragma once

#include <BaseDefine.h>
#include <memory.h>

/**
* @class CheckFlags
*  - 
*/ 
class DEFLIB_EXTERN_CLASS CheckFlags{
	enum{
		DEF_CHECK_MODE_IN_MEMORY=		0,
		DEF_CHECK_MODE_OUT_MEMORY=		1
	};

public:
	void setFlagOn(unsigned short idx);    
	void setFlagOn();
	void setFlagOff(unsigned short idx);

    unsigned short setFlagOntoOff();
    unsigned short setFlagOfftoOn();

	unsigned short getFlagOnCnt();
	unsigned short getFlagOffCnt();

	bool isFullOn();
	bool isFullOff();

	bool isOn(unsigned short idx);
	bool isOff(unsigned short idx);

	void setFullOn();
	void setFullOff();

    unsigned short getFstOn();
	unsigned short getFstOff();

	unsigned short getSize();

	CheckFlags(unsigned short count){
        arrFlags_=0;
        arrSize_=0;	
        nullIdx_=0;
        mode_=DEF_CHECK_MODE_IN_MEMORY;

		arrFlags_=new byte[count];
		memset(arrFlags_, 0, count);
		arrSize_=count;
		nullIdx_=0;
	}

	CheckFlags( byte* data, ushort count){
        arrFlags_=0;
        arrSize_=0;	
        nullIdx_=0;        

		if( mode_ == DEF_CHECK_MODE_IN_MEMORY ){
			if( arrFlags_ != 0 ) 
				delete [] arrFlags_;
		}	

		arrFlags_=data;
		memset(arrFlags_, 0, count);
		arrSize_=count;

		mode_ = DEF_CHECK_MODE_OUT_MEMORY;
	}

	virtual ~CheckFlags(){
		if( mode_ == DEF_CHECK_MODE_IN_MEMORY ) 
			delete [] arrFlags_;
	}

protected:

private:
	byte mode_;
	ushort arrSize_;
	ushort nullIdx_;
	byte* arrFlags_;
};

